package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.PostsMapper;
import com.ruoyi.system.domain.Posts;
import com.ruoyi.system.service.IPostsService;

/**
 * 用户发帖信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-08
 */
@Service
public class PostsServiceImpl implements IPostsService 
{
    @Autowired
    private PostsMapper postsMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询用户发帖信息
     * 
     * @param postId 用户发帖信息主键
     * @return 用户发帖信息
     */
    @Override
    public Posts selectPostsByPostId(Long postId)
    {
        return postsMapper.selectPostsByPostId(postId);
    }

    /**
     * 查询用户发帖信息列表
     * 
     * @param posts 用户发帖信息
     * @return 用户发帖信息
     */
    @Override
    public List<Posts> selectPostsList(Posts posts)
    {
        List<Posts> posts1 = postsMapper.selectPostsList(posts);
        for (Posts post : posts1) {
            SysUser sysUser = sysUserMapper.selectUserById(post.getUserId());
            post.setUserName(sysUser.getUserName());
        }
        return posts1;
    }

    /**
     * 新增用户发帖信息
     * 
     * @param posts 用户发帖信息
     * @return 结果
     */
    @Override
    public int insertPosts(Posts posts)
    {
        return postsMapper.insertPosts(posts);
    }

    /**
     * 修改用户发帖信息
     * 
     * @param posts 用户发帖信息
     * @return 结果
     */
    @Override
    public int updatePosts(Posts posts)
    {
        return postsMapper.updatePosts(posts);
    }

    /**
     * 批量删除用户发帖信息
     * 
     * @param postIds 需要删除的用户发帖信息主键
     * @return 结果
     */
    @Override
    public int deletePostsByPostIds(Long[] postIds)
    {
        return postsMapper.deletePostsByPostIds(postIds);
    }

    /**
     * 删除用户发帖信息信息
     * 
     * @param postId 用户发帖信息主键
     * @return 结果
     */
    @Override
    public int deletePostsByPostId(Long postId)
    {
        return postsMapper.deletePostsByPostId(postId);
    }
}
